import Message from "element-ui/packages/message/src/main";
import * as autoQAAPI from "../../api/autoQAAPI";
import {resolveTextAPI} from "../../api/autoQAAPI";

const autoQAStorage = {
    state: {},
    mutations: {},
    actions: {
        getAnswer: async ({commit}, data) => {
            try {
                let res = await autoQAAPI.autoQAAPI(data);
                if (!res) {
                    return {answer: "这个问题暂时还无法解答哦~"};
                } else {
                    return res;
                }
            } catch (e) {
                return {answer: "这个问题暂时还无法解答哦~"};
            }
        },
        resolveText: async ({commit}, data) => {
            try {
                let res = await resolveTextAPI(data);
                if (!res) {
                    Message({
                        message: "文本解析失败",
                        type: "error"
                    });
                } else {
                    Message({
                        message: "文本解析成功",
                        type: "success"
                    });
                }
                return res
            } catch (e) {
                Message({
                    message: "文本解析失败",
                    type: "error"
                });
            }
        }
    }

};

export default autoQAStorage;